<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>promise的小例子</title>
</head>
<body>
    
    <script>
        -function () {

            function buy () {
                return new Promise((resolve,reject)=>{
                    setTimeout(() => {
                        if(Math.random()>0.45){
                            resolve('I will Take it');
                        } else {
                            reject('sorry,I do not like it');
                        }
                    }, Math.random()*1000);
                });
            }

            buy().then((data)=>{
                console.log(data);
            },(err)=>{
                console.log(err);
            });

        } ();
    </script>
</body>
</html>